 jQuery(function() {
	 var serverUserData = {};
	 var closeDate = new Date();
	 jQuery("#finishDate").val(moment(closeDate).format("YYYY-MM-DD"));
		//信息片区传递保存按钮
		jQuery('.deliveryBtn').on("click",function(){
			var isTransmit = document.getElementById("isTransmit").checked;
			var url = window.rootPath + "/ui/chanceDelivery/deliverysave";
			var id = jQuery("#id1").val();
			var d;
			if($("#mainArea").val() == ""){
				$.springLemonDialog({
	  		         content: '请选择要分配的片区！',// 确认文本
	  		         clickButton: function (sender, modal, index) {// 按钮事件处理
	  		             $(this).closeDialog(modal);
	  		         }
	  		   }); 
			}
			else{
				//验证是否已分配该片区
				jQuery.ajax({
					type : 'get',
					url : window.rootPath + "/ui/chanceDelivery/validArea"+"?areaId="+$("#mainArea").val()+"&chanceId="+id,
					dataType : 'json',
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.isDelivery == "1"){
							$.springLemonDialog({
				  		         content: '该片区已分配，请重新选择片区！',// 确认文本
				  		         clickButton: function (sender, modal, index) {// 按钮事件处理
				  		             $(this).closeDialog(modal);
				  		         }
				  		   });
						}
						else{
							var targetType =$("#targetType").val();
							if(targetType == "1")
							{
								d={
										"saleArea": {"id":$("#mainArea").val()},
										"saleChance": {"id":id},
										"targetType":"1"
								};
								
							}else{
								d={
										"saleArea": {"id":$("#mainArea").val()},
										"saleChance": {"id":id},
								};
							}
							
							jQuery.ajax({
								type : 'post',
								url : url,
								data : JSON.stringify(d),
								dataType : 'json',
								contentType : 'application/json;charset=utf-8',
								success : function(data) {
									serverData1.targetType =targetType;
									serverTable1.draw();
									//serverTable.draw();
									//jQuery("#chanceDeliveryModal").modal('hide');
								}
							});
							var api= window.rootPath + "/api/chanceDeliveryTemps/"+$("#tempId").val();
							var data={
									"isReceived":"1"
							}
							jQuery.ajax({
								type : 'patch',
								url : encodeURI(api),
								data : JSON.stringify(data),
								dataType : 'json',
								contentType : 'application/json;charset=utf-8',
								success : function(data) {
									//serverTable.draw();
									//jQuery("#chanceDeliveryModal").modal('hide');
								}
							});
							serverTable.draw();
							//jQuery("#chanceDeliveryModal").modal('hide');
						}
					}
				});
					
			}
		});
		//信息部门传递保存按钮
		jQuery('.transBtn').on("click",function(){
			//验证是否可以传递部门
			jQuery.ajax({
				type : 'get',
				url : window.rootPath + "/ui/chanceDelivery/validSuperior"+"?chanceId="+jQuery("#id1").val(),
				dataType : 'json',
				contentType : 'application/json;charset=utf-8',
				success : function(data) {
					if(data.num != "0"){
						$.springLemonDialog({
			  		         content: '该信息已分配片区，不可传递！',// 确认文本
			  		         clickButton: function (sender, modal, index) {// 按钮事件处理
			  		             $(this).closeDialog(modal);
			  		         }
			  		   });
					}
					else{
						if($("#transUnit").val() == ""){
							$.springLemonDialog({
				  		         content: '请选择要传递的部门！',// 确认文本
				  		         clickButton: function (sender, modal, index) {// 按钮事件处理
				  		             $(this).closeDialog(modal);
				  		         }
				  		   }); 
						}else{
							var id = jQuery("#tempId").val();
							url =  window.rootPath + "/api/chanceDeliveryTemps/"+id;
							d={
								"receiveSuperior": $("#transUnit").val(),
								"chanceType": 2
							};
							jQuery.ajax({
								type : 'patch',
								url : encodeURI(url),
								data : JSON.stringify(d),
								dataType : 'json',
								contentType : 'application/json;charset=utf-8',
								success : function(data) {
									//操作日志
									var operateType = "信息传递部门";
									var content = "传递销售信息【"+$("#chanceName").val()+"】到【"+$("#transUnit").val()+"】";
									addOperateLog(operateType,content);
									//流转记录
									var chanceId = jQuery("#id1").val();
									addChanceFlowNode(chanceId,"",$("#transUnit").val(),"信息传递");
									
									jQuery.ajax({
										type : 'post',
										url : window.rootPath + "/ui/chanceDelivery/saveChanceDeliveryTemps?id="+id,
										dataType : 'json',
										contentType : 'application/json;charset=utf-8',
										success : function(data) {
										}
									});
									
									serverTable.draw();
									jQuery("#chanceDeliveryModal").modal('hide');
								}
							});
						}
					}
				}
			});
		});
		//信息发起协作保存按钮
		jQuery('.coopBtn').on("click",function(){
			if(jQuery('#coopSuperior').val() == ""){
				$.springLemonDialog({
	  		         content: '请选择要协作的部门！',// 确认文本
	  		         clickButton: function (sender, modal, index) {// 按钮事件处理
	  		             $(this).closeDialog(modal);
	  		         }
	  		   });
			}
			else{
				var id = jQuery("#id2").val();
				var superior = jQuery('#coopSuperior').val();
				//验证是否可以传递部门
				jQuery.ajax({
					type : 'get',
					url : window.rootPath + "/ui/chanceDelivery/validCoopSuperior"+"?chanceId="+id+"&coopSuperior="+superior,
					dataType : 'json',
					contentType : 'application/json;charset=utf-8',
					success : function(data) {
						if(data.isDelivery == "1"){
							$.springLemonDialog({
				  		         content: '已对该部门发起协作，请重新选择部门！',// 确认文本
				  		         clickButton: function (sender, modal, index) {// 按钮事件处理
				  		             $(this).closeDialog(modal);
				  		         }
				  		   });
						}
						else{
							var url = window.rootPath + "/ui/chanceDelivery/cooperationsave";
							var d={
									"receiveSuperior":superior,
									"saleChance": {"id":id},
									
									"chanceType": "1"
							};
							jQuery.ajax({
								type : 'post',
								url : url,
								data : JSON.stringify(d),
								dataType : 'json',
								contentType : 'application/json;charset=utf-8',
								success : function(data) {
									serverTable2.draw();
								}
							});
							var api= window.rootPath + "/api/chanceDeliveryTemps/"+$("#tempId").val();
							var data={
									"isReceived":"1"
							}
							jQuery.ajax({
								type : 'patch',
								url : encodeURI(api),
								data : JSON.stringify(data),
								dataType : 'json',
								contentType : 'application/json;charset=utf-8',
								success : function(data) {
									serverTable.draw();
								}
							});
						}
						serverTable.draw();
					}
				});
				
			}
			
		});
		//关闭信息选择合同弹窗引入按钮
		jQuery('#btn-reference').on('click',function(){
			var selects=getSelect("#table-usera",1);
	   	   if(selects.length>1){
	   		   $.springLemonDialog({
	   		         content: '只能操作一条记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }
	   	   else if(selects.length==0){
	   		   $.springLemonDialog({
	   		         content: '请选择要操作的记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }
	   	   var supplierCode = selects[0].supplierCode;
	   	   var contractId = selects[0].contractId;
	   	   jQuery("#contractCode").val(supplierCode);
	   	   jQuery("#contractId").val(contractId);
	   	   jQuery("#modal-find-auditor").modal('hide');
        })
		//关闭信息选择合同弹窗查询按钮
		jQuery('#btn-searchcontract').on('click',function(){
        	//getServerDate();
			if(jQuery("#searchcontract").val()) serverUserData.supplierCode=jQuery("#searchcontract").val();
			serverUserTable.draw();
        });
		//关闭信息中选择按钮
		jQuery('#choose').on("click",function(){
			jQuery("#modal-find-auditor").modal('show');
			serverUserTable = jQuery('#table-usera').DataTable(
							{
								"serverSide" : true,
								"iDisplayLength" : 4,
								"ordering" : false,
								"ajax" : {
									"dataType" : "json",
									"type" : "get",
									"cache" : false,
									"url" : window.rootPath + '/ui/contract/getpage1',
									"data" : function(d) {
										return $.extend({}, d, serverUserData);
									}
								},
								columns : [
										{
											// 1序号
											data : null,
							                defaultContent : ""// 排序   1
										},{// 6选择按钮
											data: null,
								            defaultContent: "",
								            render: function (data, type, full, meta) {
								            	var id=data.id
								            	var operate ='<input type="checkbox" class="checkchildContract">';
								            	return operate;
								            }  
										},
										{// 2合同号
											data : "supplierCode",
										},
										{// 3合同类型
											data : 'contractType'
										},

										{// 4状态
											data : 'state'
										},
										{// 5总价
											data : 'totalSum'
										}
								],
								"drawCallback" : function(oSettings) {
									var k = 0;
									var total = oSettings.aiDisplay.length
											+ oSettings._iDisplayStart;

									for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
										$(
												'td:eq(0)',
												oSettings.aoData[oSettings.aiDisplay[k]].nTr)
												.text(i + 1);
										k++;
									}

									serverUserTable.off('click', 'tr');
									serverUserTable
											.on(
													'click',
													'tr',
													function(event) {
														event = event || window.event;
														var target = event.target
																|| event.scrElement;
														var data = serverUserTable
																.row(this).data();

														if (target.className
																.indexOf('app-select-user') != -1) {
															onSelectUser(data);
														}
														return;
													});
								}
							});
			var selectedUser = null;
			var currentAuditor = null;
			var onSelectUser = function onSelectUser(data) {
				selectedUser = data;
			};
		});
		//信息关闭弹窗保存按钮
		jQuery('.closeBtn').on("click",function(){
			var id = jQuery("#id3").val();
			jQuery(".closeBtn").attr("disabled","disabled");
			url =  window.rootPath + "/api/chances/"+id;
			var contractId = $("#contractId").val();
			d={
				"closeReason": $("#reason").val(),
				"contractCode": $("#contractCode").val(),
				"isSucceed": $("#isSucceed").val(),
				"finishDate": $("#finishDate").val(),
				"contractId":contractId
			};
			jQuery.ajax({
				type : 'patch',
				url : encodeURI(url),
				data : JSON.stringify(d),
				dataType : 'json',
				contentType : 'application/json;charset=utf-8',
				success : function(data) {
					var operateType = "信息分配片区";
					var content = "关闭销售信息【"+$("#chanceName").val()+"】";
					addOperateLog(operateType,content);
					//写入流转记录
					addChanceFlowNode(id,"","关闭","关闭信息")
					serverTable.draw();
					jQuery(".closeBtn").removeAttr("disabled");
					jQuery("#closeChanceModal").modal('hide');
					
					var api= window.rootPath + "/api/chanceDeliveryTemps/"+$("#tempId").val();
					var data={
							"isReceived":"1"
					}
					jQuery.ajax({
						type : 'patch',
						url : encodeURI(api),
						data : JSON.stringify(data),
						dataType : 'json',
						contentType : 'application/json;charset=utf-8',
						success : function(data) {
							alert("信息已关闭！！");
							serverTable.draw();
						}
					});
				}
			});
		});
	 var serverData = {};
	 serverData.key ='';
	 serverData.state = '0';
	 serverData.targetType = '2';
	    var serverTable;
	    jQuery(document).ready(function () {
	    	serverTable = jQuery('#chanceDeliveryTable').DataTable({
		        "serverSide": true,
		        "ordering": false,
		        "ajax": {
		            "dataType": "json",
		            "type": "get",
		            "cache": false,
		            "url":window.rootPath+ '/ui/chanceDelivery/getpage1',
		            "data": function (d) {
		                return $.extend({}, d, serverData);
		            }
		        },
		        columns: [
		            {
		            data: null
		            },
		            {
		                data: null,
		                defaultContent: "",
		                render: function (data, type, full, meta) {
		                	var closeReason = data.closeReason;
		                	var operate
		                	var userSuperior = $("#userSuperior").val();
		                	if(data.chanceType != 2 || userSuperior == data.receiveSuperior){
		                		operate ='<input type="checkbox" class="checkchild">';
		                	}
		                    return operate;

		                }
		            },
		            {
		                data: null,
		                defaultContent: "",
		                render: function (data, type, full, meta) {
		                	var closeReason = data.saleChance.closeReason;
		                	var userSuperior = $("#userSuperior").val();
		                	var chanceType = data.chanceType;
		                	var receiveSuperior=data.receiveSuperior;
		                	
		                	var dOut;
		                	if(closeReason != null){
		                		if(chanceType == "0" ){
		                			dOut ='<p><span class="badge" style="background-color:red;font-family:arial;color:bule">本部信息[已关闭-'+data.saleChance.isSucceed+']</span></p>';
		                		}
			                	else if(chanceType == "1"){
			                		dOut ='<p><span class="badge" style="background-color:green;font-family:arial;color:bule">协作信息[已关闭-'+data.saleChance.isSucceed+']</span></p>';
			                	}
			                	else if(chanceType=='2'){
			                		dOut ='<p><span class="badge" style="background-color:green;font-family:arial;color:bule">传递信息[已关闭-'+data.saleChance.isSucceed+']</span></p>';
			                	}
		                	}else{
		                		if(chanceType == "0" ){
			                		dOut ='<p><span class="badge" style="background-color:red;font-family:arial;color:bule">本部信息</span></p>';
			                	}
			                	else if(chanceType == "1"){
			                		dOut ='<p><span class="badge" style="background-color:green;font-family:arial;color:bule">协作信息</span></p>';
			                	}
			                	else if(chanceType=='2'){
			                		dOut ='<p><span class="badge" style="background-color:green;font-family:arial;color:bule">传递信息</span></p>';
			                	}
		                	}
		                    return dOut;

		                }
		            },
		            {
		            	data: 'saleChance.name',
		            	render:function(data,type,full,meta){
		            		if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		            },
		            {
		            	data: 'saleChance.chancePriority'
		            },
		            {
		                data: 'saleChance.source'
		            },
		            {
		                data: 'saleChance.sourceUnit',
		                render:function(data,type,full,meta){
		                	if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		                
		            },
		            {
		                data: 'saleChance.user.empLogin.userName'
		                
		            },
		            {
		            	data: 'saleChance.business'
		            		
		            },
		            {
		            	data: 'saleChance.user.saleArea.superiorArea'
		            },
		            {
		                data: 'saleChance.sourceOfferInfo',
		                render:function(data,type,full,meta){
		                	if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		                
		            },
		            {
		                data: 'saleChance.projectState',
		                render:function(data,type,full,meta){
		                	if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		            },
		            {
		                data: 'saleChance.deviceState',
		                render:function(data,type,full,meta){
		                	if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		            },
		            {
		                data: 'saleChance.sourcePower'
		            },
		            {
		                data: 'saleChance.orderAmount'
		                
		            },
		            {
		                data: 'saleChance.orderUnit',
		                render:function(data,type,full,meta){
		                	if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		                
		            },
		            {
		                data: 'saleChance.orderPerson'
		                
		            },
		            {
		                data: 'saleChance.orderPersonPhone'
		                
		            },
		            {
		                data: 'saleChance.orderUnitAddr',
		                render:function(data,type,full,meta){
		                	if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		                
		            },
		            {
		            	data: 'saleChance.createTime',
		            	render : function(data,type, full,meta) {
								if (data) 
								{
									return moment(data).format("YYYY-MM-DD");
								}
		            	}
		                
		            },
		            {
		                data: 'saleChance.closeReason',
						render:function(data,type,full,meta){
							if(data == null || data == undefined || data == ""){
								return data;
							}else{
								return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
							}
						}
		                
		            },
		          ],
		        "drawCallback": function (oSettings) {
		            var k = 0;
		            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

		            for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
		                $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
		                k++;
		            }

		            serverTable.off('click', 'tr');
		            serverTable.on('click', 'tr', function (event) {
		                event = event || window.event;
		                var target = event.target || event.scrElement;
		                var data = serverTable.row(this).data();

		                return;
		            });
		        }
		    });
	    	});
	    //传递片区
	    jQuery('.del-btn').on('click', function() {
	    	var selects=getSelect("#chanceDeliveryTable",1);
	   	   if(selects.length>1){
	   		   $.springLemonDialog({
	   		         content: '只能操作一条记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }
	   	   else if(selects.length==0){
	   		   $.springLemonDialog({
	   		         content: '请选择要操作的记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }else if(selects.length==1){
	   		 var id=selects[0].saleChance.id;
	   		if(selects[0].saleChance.closeReason != null){
	   			$.springLemonDialog({
	   		         content: '该信息已关闭不可操作！',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   });
	   		 }else{
	   			$("#id1").val(id);
	  		     $("#transUnit").val('');
	  		     $("#mainArea").val('');
	  		     $("#targetType").val(selects[0].chanceType);
	  		     $("#tempId").val(selects[0].id);
	  		     $("#chanceName").val(selects[0].saleChance.name);
	  		     jQuery("#info").text("");
	  		     $("#cooperate1").removeClass("hide");
 		    	 $("#cooperate2").removeClass("hide");
	  		     if(selects[0].chanceType == 1){
	  		    	$("#cooperate1").addClass("hide");
	  		    	$("#cooperate2").addClass("hide");
	  		     }
	  		     
	  		     jQuery("#chanceDeliveryModal").modal('show');
	  		     serverData1.chanceId =id;
	  		     serverData1.targetType =selects[0].chanceType;
	  		     serverTable1.draw(); 
	   		 }
	   		
	   	   }
	   		
	    });
//发起协作
	  jQuery('.coop-btn').on('click', function() {
		  var selects=getSelect("#chanceDeliveryTable",1);
	   	   if(selects.length>1){
	   		   $.springLemonDialog({
	   		         content: '只能操作一条记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }
	   	   else if(selects.length==0){
	   		   $.springLemonDialog({
	   		         content: '请选择要操作的记录',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   	   }else if(selects.length==1){
	   		 var id=selects[0].saleChance.id;
	   		var chanceType=selects[0].chanceType;
	   		 if(selects[0].saleChance.closeReason != null){
	   			$.springLemonDialog({
	   		         content: '该信息已关闭不可操作！',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   });
	   		 }
	   		 else if(chanceType =="1"){
	   			$.springLemonDialog({
	   		         content: '该信息已是协助信息！',// 确认文本
	   		         clickButton: function (sender, modal, index) {// 按钮事件处理
	   		             $(this).closeDialog(modal);
	   		         }
	   		   }); 
	   		 }
	   		 else{
	   			$("#id2").val(id);
	    		jQuery("#coopSuperior").val('');
	            jQuery("#areaName").val('');
	            jQuery("#areaName1").val('');
	            jQuery("#areaName2").val('');
	            jQuery("#areaName3").val('');
	            $("#chanceName").val(selects[0].saleChance.name);
	    		jQuery("#distributeModal").modal('show');
	    		serverData2.chanceId = id;
	    		serverTable2.draw();
	   		 }
	   		 
	   	   }
	  });
	    //关闭信息
	    jQuery('.close-btn').on('click', function() {
	    	var selects=getSelect("#chanceDeliveryTable",1);
		   	   if(selects.length>1){
		   		   $.springLemonDialog({
		   		         content: '只能操作一条记录',// 确认文本
		   		         clickButton: function (sender, modal, index) {// 按钮事件处理
		   		             $(this).closeDialog(modal);
		   		         }
		   		   }); 
		   	   }
		   	   else if(selects.length==0){
		   		   $.springLemonDialog({
		   		         content: '请选择要操作的记录',// 确认文本
		   		         clickButton: function (sender, modal, index) {// 按钮事件处理
		   		             $(this).closeDialog(modal);
		   		         }
		   		   }); 
		   	   }else if(selects.length==1){
		   		 var id=selects[0].saleChance.id;
		   		$("#id3").val(id);
		   		$("#tempId").val(selects[0].id);
		   		if(selects[0].saleChance.closeReason != null){
		   			$.springLemonDialog({
		   		         content: '该信息已关闭！',// 确认文本
		   		         clickButton: function (sender, modal, index) {// 按钮事件处理
		   		             $(this).closeDialog(modal);
		   		         }
		   		   });
		   		 }
		   		else{
		   			$("#chanceName").val(selects[0].saleChance.name);
		   			jQuery("#closeChanceModal").modal('show');
		   			jQuery("#contractCode").val('');
		   			jQuery("#contractId").val('');
		   			
		   		}
	    		
		   	   }	    	
	    });
	    //查看详情
	    jQuery('.detail-btn').on('click', function() {
	    	var selects=getSelect("#chanceDeliveryTable",1);
	  	   if(selects.length>1){
	  		   $.springLemonDialog({
	  		         content: '只能操作一条记录',// 确认文本
	  		         clickButton: function (sender, modal, index) {// 按钮事件处理
	  		             $(this).closeDialog(modal);
	  		         }
	  		   }); 
	  	   }
	  	   else if(selects.length==0){
	  		   $.springLemonDialog({
	  		         content: '请选择要操作的记录',// 确认文本
	  		         clickButton: function (sender, modal, index) {// 按钮事件处理
	  		             $(this).closeDialog(modal);
	  		         }
	  		   }); 
	  	   }else if(selects.length==1){
	  		 var id=selects[0].saleChance.id;
	  		window.location = window.rootPath + "/ui/chance/detail"+"?chanceId="+id;  
	  	   }
		});
	  //传递片区弹窗服务器分页
	    var serverData1 = {};
	    var serverTable1;

	    jQuery(document).ready(function () {
	    serverTable1 = jQuery('#chanceDeliveryModuleTable').DataTable({
	        "serverSide": true,
	        "ordering": false,
	        "ajax": {
	            "dataType": "json",
	            "type": "get",
	            "cache": false,
	            "url":window.rootPath+ '/ui/chanceDelivery/getModulePage',
	            "data": function (d) {
	                return $.extend({}, d, serverData1);
	            }
	        },
	        columns: [
	            {
	            data: null,
	            defaultContent: "",
                render: function (data, type, full, meta) {
                	var isReceived = data.isReceived;
                	var dOut;
                	if(isReceived != "1"){
                		dOut ='<input type="checkbox" class="checkAllArea">';
                	}
                	
                    return dOut;

                }
	            },
	            {
	            	data: null,
	                defaultContent: "",
	                render: function (data, type, full, meta) {
	                	var isReceived = data.isReceived;
	                	var rejectReason = data.rejectReason;
	                	var dOut;
	                	if(isReceived == "1" && rejectReason == null){
	                		dOut ='<p><span class="badge" style="background-color:green;font-family:arial;color:bule">已接收</span></p>';
	                	}
	                	else if(rejectReason != null){
	                		dOut ='<p><span class="badge" style="background-color:red;font-family:arial;color:bule">已退回</span></p>';
	                	}
	                	else{
	                		dOut ='<p><span class="badge" >未接收</span></p>';
	                	}
	                    return dOut;

	                }
		        },
	            {
	                data: 'saleArea.superior',
	               
	            },
	            {
	                data: 'saleArea.areaName',
	            }
	          ],
	        "drawCallback": function (oSettings) {
	            var k = 0;
	            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

	            
	        }
	            });
	        });
	    // 删除分配片区按钮
		jQuery('.deleteDelivery').on('click', function() {
			var selects=getSelect("#chanceDeliveryModuleTable",0);
	    	var url = window.rootPath + "/ui/chanceDelivery/deleteArea";
	 	   delSelect(selects,url,serverTable1) 
		});
		  //发起协作弹窗数据分页
	    var serverData2 = {};
	    var serverTable2;

	    jQuery(document).ready(function () {
	    serverTable2 = jQuery('#distributeModuleTable').DataTable({
	        "serverSide": true,
	        "ordering": false,
	        "ajax": {
	            "dataType": "json",
	            "type": "get",
	            "cache": false,
	            "url":window.rootPath+ '/ui/chanceDelivery/getModulePageCoop',
	            "data": function (d) {
	                return $.extend({}, d, serverData2);
	            }
	        },
	        columns: [
	            {
	            data: null,
	            defaultContent: "",
                render: function (data, type, full, meta) {
                	var isReceived = data.isReceived;
                	var dOut;
                	if(isReceived != "1"){
                		dOut ='<input type="checkbox" class="checkAllSuperior">';
                	}
                	
                    return dOut;

                }
	            },
	            {
	            	data: null,
	                defaultContent: "",
	                render: function (data, type, full, meta) {
	                	var isReceived = data.isReceived;
	                	var rejectReason = data.rejectReason;
	                	var dOut;
	                	if(isReceived == "1"){
	                		dOut ='<p><span class="badge" style="background-color:green;font-family:arial;color:bule">已接收</span></p>';
	                	}
	                	else if(rejectReason != null){
	                		dOut ='<p><span class="badge" style="background-color:red;font-family:arial;color:bule">已退回</span></p>';
	                	}
	                	else{
	                		dOut ='<p><span class="badge" >未接收</span></p>';
	                	}
	                    
	                    return dOut;

	                }
		        },
	            {
	                data: 'receiveSuperior',
	               
	            },
	            
	          ],
	        "drawCallback": function (oSettings) {
	            var k = 0;
	            var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

	            
	        }
	            });
	        });
	 // 删除协作部门按钮
		jQuery('.deleteCoop').on('click', function() {
			var selects=getSelect("#distributeModuleTable",0);
	    	var url = window.rootPath + "/ui/chanceDelivery/deleteCoop";
	 	   delSelect(selects,url,serverTable2) 
		});
	    //查询
	    jQuery('.searchBtn').on('click', function() {
			serverData.key = jQuery('#keyword').val();
			var state=$('input:radio[name="isReceived"]:checked').val();
			var targetType=$('input:radio[name="targetType"]:checked').val();
			serverData.targetType = targetType;
			serverData.state = state;
			serverTable.draw();
		});
		// 撤销查询
		jQuery('.cancelBtn').on("click", function() {
			jQuery('#keyword').val('');
			serverData.key = '';
			var state=$('input:radio[name="isReceived"]:checked').val();
			var targetType=$('input:radio[name="targetType"]:checked').val();
			serverData.targetType = targetType;
			serverData.state = state;
			serverTable.draw();
		});
		 //获取选中状态
		 $(function(){
			  $(":radio").click(function(){
				  serverData.key = jQuery("#keyword").val();
				  var state=$('input:radio[name="isReceived"]:checked').val();
				  var targetType=$('input:radio[name="targetType"]:checked').val();
				  serverData.state = state;
				  serverData.targetType = targetType;
				  serverTable.draw();
			  });
		});
		   ///////列表中的全选
	    $("#checkAll").click(function(){
	    	var check = $(this).prop("checked");
	        $(".checkchild").prop("checked", check);
		});
	    ///////列表中的全选
	    $("#checkArea").click(function(){
	    	var check = $(this).prop("checked");
	        $(".checkAllArea").prop("checked", check);
		});
	///////列表中的全选
	    $("#checkSuperior").click(function(){
	    	var check = $(this).prop("checked");
	        $(".checkAllSuperior").prop("checked", check);
		});
});
